using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

/// <summary>
/// This Class is Created by Akash Saxena on 6th Oct 2007,
/// This will contain all common function 
/// </summary>
public class CommonFunction
{
	public CommonFunction()
	{
		//
		// TODO: Add constructor logic here
		//
    }

    Manager objManager = new Manager(true,"ConnectionString");
    //private Variables
    private DateTime dDateOFCreation;
    private string sCouponCode="";
    private bool bIsActive=false;
    private int iDoctorID=0;
    private int iDentistID=0;
    private DateTime dUsedAsOn;
    private string _UrlDoctorSpecialty = "doctors_by_specialty/";
  
    //Public Property
    public DateTime DateOFCreation
    {
        get { return dDateOFCreation; }
        set { dDateOFCreation = value; }

    }
    public string CouponCode
    {
        get { return sCouponCode; }
        set { sCouponCode = value; }

    }
    public bool IsActive
    {
        get { return bIsActive; }
        set { bIsActive = value; }

    }
    public int DoctorID
    {
        get { return iDoctorID; }
        set { iDoctorID = value; }

    }
    public int DentistID
    {
        get { return iDentistID; }
        set { iDentistID = value; }

    }
    public DateTime UsedAsOn
    {
        get { return dUsedAsOn; }
        set { dUsedAsOn = value; }

    }
    //Added this property  at 250808 by ranjeet for URL rewriting purpose

    public  string UrlDoctorSpecialty
    {
        get { return _UrlDoctorSpecialty; }
        set { _UrlDoctorSpecialty = value; }

    }

    //End
    #region  Coupon
    /// <summary>
    ///  This function is used to insert Generated 
    /// Coupon Code Details in Coupon Table. 
    /// </summary>
    /// <author>Akash Saxena </author>
    /// <date>06 Oct, 2007</date>
   
    public int InsertCoupons(int doctorType)
    {
        int iresult = 0;
        try
        {
            SqlParameter[] sqlparam = new SqlParameter[7];
            sqlparam[0] = new SqlParameter("@SNO", SqlDbType.BigInt);
            sqlparam[0].Value = 0;
            sqlparam[1] = new SqlParameter("@DateOFCreation ", dDateOFCreation);
            sqlparam[2] = new SqlParameter("@CouponCode", sCouponCode);
            sqlparam[3] = new SqlParameter("@IsActive", bIsActive);
            sqlparam[4] = new SqlParameter("@DoctorID", iDoctorID);
            sqlparam[5] = new SqlParameter("@DoctorType", SqlDbType.BigInt);
            sqlparam[5].Value = doctorType;
            //sqlparam[6] = new SqlParameter("@UsedAsOn", dUsedAsOn);
            sqlparam[6] = new SqlParameter("@Result", SqlDbType.SmallInt);
            sqlparam[6].Direction = ParameterDirection.Output;
            objManager.ExecuteUpdate("[InsertCoupons]", sqlparam);
            return Convert.ToInt32(sqlparam[6].Value);

        }
        catch (Exception ex)
        {
            HttpContext.Current.Response.Write(ex.Message.ToString());

        }
        return iresult;
    }
    #endregion
    public static string urlconversion(string StringValue)
    {
        string regex = "((www\\.|(http|https|ftp|news|file)+\\:\\/\\/)[&#95;.a-z0-9-]+\\.[a-z0-9\\/&#95;:@=.+?,##%&~-]*[^.|\\'|\\# |!|\\(|?|,| |>|<|;|\\)])";
        Regex r = new Regex(regex, RegexOptions.IgnoreCase);
        string str1 = r.Replace(StringValue, "<a href=\"$1\" rel=\"nofollow\"  target=\"_blank\">$1</a>").Replace("href=\"www", "href=\"http://www");
        //Return (r.Replace(msg, "<a href=""$1"" title=""Click to open in a new window or tab"" target=""&#95;blank"">$1</a>").Replace("href=""www", "href=""http://www"))
        Regex emailregex = new Regex("([a-zA-Z_0-9.-]+\\@[a-zA-Z_0-9.-]+\\.\\w+)", (RegexOptions.IgnoreCase | RegexOptions.Compiled));
        str1 = emailregex.Replace(str1, "<a rel='nofollow' href=mailto:$1>$1</a>");

        return str1;

    }
    public static string ToTitleCase(string StringValue)
    {
        System.Globalization.TextInfo txtInfo = System.Globalization.CultureInfo.CurrentCulture.TextInfo;
        return txtInfo.ToTitleCase(StringValue);
    }
}

